

// node 开发接口服务器 


const http = require("http")
const hostname = "0.0.0.0"
const port = 6600;

// import word from "./demo.js"
const word = require("./demo")
const {names,list,text} = require("./many")

const User = require("./user");
const u1 = new User("zkl",28,"2107-天道酬勤 ")
console.log(u1)

const Student = require("./student")
const s1 = new Student("小名",22,"我要月薪20W",100)

// req 请求  req.header  req.params req.query req.url  
// res 响应
const server = http.createServer((req,res)=>{
    // console.log(req)
    if(req.url!=="/favicon.ico"){
      console.log(req.url)
      res.writeHead(200,{'content-Type':"text/html;charset=utf8"});
      res.write("<h2> Node is Javascript Server </h2>")
      res.write("<h2> 学好Node, 开发简单的接口  </h2>")
      res.write("模块化编程 把复杂的业务逻辑拆分为简单独立可复用的单元模块")
      res.write("<h2>为了让JS 不仅仅运行在客户端,还可以运行在服务器端,设计开发了commonJS规范 </h2>")
      res.write("<h2>NodeJS 和 Webpack 都遵循 commonJS 规范  </h2>")
      res.write(`<h2>${word}</h2>`)
      res.write(`<h2>${names}</h2>`)
      res.write(`<h2>${list}</h2>`)
      res.write(`<h2>${text}</h2>`)
      res.write(`<h2>${u1.name} - ${u1.word} -- ${u1.say()} -- ${User.hobby} </h2>`)
      res.write(`<h2>${s1.name} - ${s1.word}- ${s1.score} -- ${s1.say()} -- ${Student.hobby} </h2>`)

      res.end();
    }

})

server.listen(port,hostname,()=>{
  console.log("my server is running at "+port);
})